// components/roll-news/index.js
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    index:0,
    newsList:[
      "新功能正在持续完善中~",
    ],
    animation:true,
    new:''
  },
  lifetimes:{
    attached(){
      wx.request({
        url: 'https://lib.apisev.cn/config/rollnews.json',
        success:res=>{
          console.log(res)
          let news = res.data.news;
          this.setData({
            newsList:news,
            new:news[0],
            index:1
          })
        }
      })
      this.Timer();
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    Timer(){
      var that = this;
      setInterval(function(){
        // console.log('触发定时器')
        var news = that.data.newsList;
        var index = that.data.index;
        that.setData({
          new:news[index],
          index:(index+1)%(news.length)
        })
      },10000)
    }
  }
})
